
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:h_flutter_119/page/find/attention/AttentionPage.dart';
import 'package:h_flutter_119/page/home/HomePage.dart';
import 'package:h_flutter_119/page/rank/EyeRankPage.dart';

class EyeFindPage extends StatefulWidget{

  @override
  State<StatefulWidget> createState() => EyeFindPageState();
  
}

class EyeFindPageState extends State<EyeFindPage> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin{

  @override
  bool get wantKeepAlive => true;

  List<String> tabList = ["关注","周排行","月排行","总排行"];
  late TabController _tabController;
  late PageController _pageController;
  List<Widget> pages = [];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: tabList.length, vsync: this);
    _pageController = PageController();
    setState((){
      pages.add(AttentionPage());
      pages.add(EyeRankPage('weekly'));
      pages.add(EyeRankPage('monthly'));
      pages.add(EyeRankPage('historical'));
    });
  }

  @override
  void dispose() {
    super.dispose();
    _tabController.dispose();
    _pageController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        _creatTabbar(),
        Expanded(child: PageView(
          controller: _pageController,
          onPageChanged: (index){
            _tabController.index = index;
          },
          children: pages,
        )),
      ],
    );
  }

  Widget _creatTabbar() {
    return Container(
      width: double.infinity,
      child: TabBar(
        controller: _tabController,
        tabs: tabList.map((e) => Tab(text: e)).toList(),
        labelColor: Colors.black,
        labelStyle: TextStyle(fontSize: 32.sp,fontWeight: FontWeight.bold),
        unselectedLabelColor: Colors.black38,
        unselectedLabelStyle: TextStyle(fontSize: 30.sp,fontWeight: FontWeight.normal),
        indicatorColor: Colors.black,
        indicatorWeight: 6.w,
        indicatorPadding: EdgeInsets.symmetric(horizontal: 50.w),
        isScrollable: true,
        onTap: (index){
          _pageController.jumpToPage(index);
        },
      ),
    );
  }


}